
function checkInputName(){
    var tNameTf = document.getElementById("nameTf");
    var tInputTips = document.getElementById("inputTip");

    var tNameLen = tNameTf.value.length;
    if (tNameLen < 1){
        tInputTips.innerText = "姓名不能为空";
        tInputTips.style.color = "red";
        tNameTf.style.borderColor = "red"
    }
    else if (tNameLen > 3 && tNameLen < 15){
        tInputTips.innerText = "姓名输入正确";
        tInputTips.style.color = "green";
        tNameTf.style.borderColor = "green";
    }
    else{
        tInputTips.innerText = "必填, 长度为4~16个字符";
        tInputTips.style.color = "gray";
        tNameTf.style.borderColor = "gray";
    }
    console.log("inputName: " + tNameTf.value + " " + tNameLen);
    return false;
}

function testPromise(){
    console.log("testPromise click");
    new Promise(function (resolve, reject){
        setTimeout(function () {
            console.log("First");
            resolve();
        }, 1000);
    }).then(function (){
        return new Promise(function (resolve, reject) {
            setTimeout(() => {
                console.log("Second");
                resolve();
            }, 4000);
        });
    }).then( () => {
        setTimeout(() => {
            console.log("Third");
        }, 3000);
    });

}

function testPromise2(){
    const promise = new Promise((resolve, reject) => {
        setTimeout(() => {
            if (Math.random() < 0.5){
                resolve('success')
            }
            else{
                reject('error')
            }
        }, 1000);
    });

    promise.then(result => {
        console.log(result);
    }).catch(error => {
        console.log(error);
    });
}